<?php

/**
 * @filename RbacAction.class.php 
 * @encoding UTF-8 
 * @author yuzhiyuan <307090870@qq.com>
 * @copyright copyright 2013 (c) Emagsoftware Technology Co., Ltd. All Rights reserved.
 * @license ……
 * @datetime 2013-6-23  16:49:03
 * @version 1.0
 * @Description
  */

class RbacAction extends BaseAction {
    //用户列表
    public function index(){
        $this->display();
    }
    //角色列表
    public function role(){
        $rdb = M('Role');
        $list = $rdb->select();
        $this->assign('list',$list);
        $this->display();
    } 
    
    //节点列表
    public function node(){
  
        $rdb = M('Node');
        $list = $rdb->field('id,name,title,pid')->order('sort')->select();
        $list = node_merge($list);
  //      p($list);exit;
        $this->assign('node',$list);
        $this->display();
    }
    //添加用户
    public function addUser(){
        $this->display();
    }
    
    //添加角色
    public function addRole(){
        $this->display();
    }
    public function doAddRole(){
        $rdb = M('Role');
        if($rdb->create()){
            if($rdb->add()){
                $this->success('添加成功！',U('Admin/Rbac/role'));
            }else{
                $this->error('添加失败！');
            }
        }else{
            $this->error($rdb->getError());
        }
        
    }
    //添加节点
    public function addNode(){
        $this->pid = I('pid',0,intval);
        $this->level = I('level',1,intval);
        
        switch ($this->level){
            case 1 :
                $this->type='应用';
                break;
            case 2 :
                $this->type='控制器';
                break;
            case 3 :
                $this->type='动作';
                break;
        }
        $this->display();
    }
    public function doAddNode(){
        $rdb = M('Node');
        if($rdb->create()){
            if($rdb->add()){
                $this->success('添加成功！',U('Admin/Rbac/node'));
            }else{
                $this->error('添加失败！');
            }
        }else{
            $this->error($rdb->getError());
        }
    }
}
